﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ninject.Modules;
using Ninject.Web.Common;
using Example.Base.Entities;
using Example.Base.Interfaces.Validators;
using Example.Data.Context;
using Example.Data.Context.Interfaces;
using Example.Data.Repositories;
using Example.Base.Interfaces.Repositories;
using Example.Base.Interfaces.DataSources;
using Example.Base.Interfaces.Services;
using Example.Data.Services;
using System.Data.SqlClient;
using Example.Data.Validators;
using Example.Data.Services.DataServices;
using Example.Base.Interfaces.Services.DataServices;
using System.Data.Entity;

namespace Example.Data
{
    public class DataContainer : NinjectModule  
    {
        #region Overrides of NinjectModule

        public override void Load()
        {
            // Base interfaces initialization
            Kernel.Bind<IDataContext>().To<DataContext>().InSingletonScope();
            Kernel.Bind<IDatabase>().To<DataContext>().InSingletonScope();
            Kernel.Bind(typeof(IRepository<>)).To(typeof(Repository<>)).InRequestScope();

            // Services registration
            Kernel.Bind<IAuthenticateService>().To<AuthenticateService>().InRequestScope();
            Kernel.Bind<IRegistrationService>().To<RegistrationService>().InRequestScope();
            Kernel.Bind<IConfigurationService>().To<ConfigurationService>();
            Kernel.Bind<IDataService<Region>>().To<WeatherService>().InRequestScope();
            Kernel.Bind<IDataService<IEnumerable<Tweet>>>().To<TwitterService>().InRequestScope();

            // Validators registration
            Kernel.Bind(typeof(IValidator<>)).To(typeof(BaseValidator<>));
            Kernel.Bind<IValidator<User>>().To<UserValidator>();

            Database.SetInitializer(new DatabaseInitializer());
        }

        #endregion
    }
}
